﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace RemoteObject
{
    public class FileDistributionRequestor
    {
        private static FileDistributionRequestor instance;
        private RemoteObject.RemoteObjectDownloader proxyObjectTcp;
        private List<DownloadJobTicket> list;

        public static FileDistributionRequestor getInstance()
        {
            if (instance == null) instance = new FileDistributionRequestor();
            return instance;
        }

        private FileDistributionRequestor()
        {
            proxyObjectTcp = (RemoteObject.RemoteObjectDownloader)Activator.GetObject(typeof(RemoteObject.RemoteObjectDownloader), Common.CloudServerURL);
            list = proxyObjectTcp.GetFileDistributionRequest();

            Thread syncThread = new Thread(new ThreadStart(Sync));
            syncThread.Start();
        }

        public void Sync()
        {
            do
            {
                list = proxyObjectTcp.GetFileDistributionRequest();
                Thread.Sleep(3000);
            } while (true);
         }

        public List<DownloadJobTicket> GetFileDistributionInfo()
        {
            return list;
        }
    }
}
